//package com.hly.poitool.util;
//
//import org.apache.commons.compress.archivers.dump.InvalidFormatException;
//import org.apache.poi.xwpf.usermodel.*;
//import org.openxmlformats.schemas.drawingml.x2006.main.CTGraphicalObject;
//import org.openxmlformats.schemas.drawingml.x2006.main.CTPoint2D;
//import org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties;
//import org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D;
//import org.openxmlformats.schemas.drawingml.x2006.wordprocessingDrawing.CTAnchor;
//import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTDrawing;
//import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTPicture;
//import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTR;
//
//import java.io.IOException;
//import java.io.InputStream;
//
///**
// * @author : Jack Hao
// * @Date : 2022/4/1 11:17
// * @description :
// */
//public class MyXWPFRun extends XWPFRun {
//    public MyXWPFRun(CTR r, IRunBody p) {
//        super(r, p);
//    }
//
//    public MyXWPFRun(CTR r, XWPFParagraph p) {
//        super(r, p);
//    }
//
//    /**
//     * Adds a picture to the run. This method handles
//     * attaching the picture data to the overall file.
//     * 复制原本的方法，加入了是否悬浮图片；在加入图片的便宜位置参数--zhengmeng
//     * x和y的取值：1厘米=360045
//     */
//    public XWPFPicture addPicture2(InputStream pictureData, int pictureType, String filename, int width, int height, boolean isXuanfu, int x, int y)
//            throws InvalidFormatException, IOException, org.apache.poi.openxml4j.exceptions.InvalidFormatException {
//        String relationId;
//        XWPFPictureData picData;
//
//        // Work out what to add the picture to, then add both the
//        //  picture and the relationship for it
//        // TODO Should we have an interface for this sort of thing?
//        if (this.getParent().getPart() instanceof XWPFHeaderFooter) {
//            XWPFHeaderFooter headerFooter = (XWPFHeaderFooter) this.getParent().getPart();
//            relationId = headerFooter.addPictureData(pictureData, pictureType);
//            picData = (XWPFPictureData) headerFooter.getRelationById(relationId);
//        } else {
//            @SuppressWarnings("resource")
//            XWPFDocument doc = this.getParent().getDocument();
//            relationId = doc.addPictureData(pictureData, pictureType);
//            picData = (XWPFPictureData) doc.getRelationById(relationId);
//        }
//
//        // Create the drawing entry for it
//        try {
//            CTDrawing drawing = run.addNewDrawing();
////            CTInline inline = drawing.addNewInline();
//
//            //*************修改 zhengmeng
//            CTAnchor inline = drawing.addNewAnchor();
//            // Do the fiddly namespace bits on the inline
//            // (We need full control of what goes where and as what)
//            String xml =
//                    "<a:graphic xmlns:a=\"" + CTGraphicalObject.type.getName().getNamespaceURI() + "\">" +
//                            "<a:graphicData uri=\"" + CTPicture.type.getName().getNamespaceURI() + "\">" +
//                            "<pic:pic xmlns:pic=\"" + CTPicture.type.getName().getNamespaceURI() + "\" />" +
//                            "</a:graphicData>" +
//                            "</a:graphic>";
//            InputSource is = new InputSource(new StringReader(xml));
//            org.w3c.dom.Document doc = DocumentHelper.readDocument(is);
//            inline.set(XmlToken.Factory.parse(doc.getDocumentElement(), DEFAULT_XML_OPTIONS));
//
//            // Setup the inline
//            inline.setDistT(0);
//            inline.setDistR(0);
//            inline.setDistB(0);
//            inline.setDistL(0);
//
//            //*********************修改zhengmeng**********************************
//            inline.setSimplePos2(false);
//            inline.setRelativeHeight(251658240);//查了文档 ，也试过，没找到作用位置，先放着
//            inline.setBehindDoc(isXuanfu);//重点，浮于文字上方
//            inline.setLocked(false);
//            inline.setLayoutInCell(true);
//            inline.setAllowOverlap(true);
//
//            CTPoint2D simplePost = inline.addNewSimplePos();
//            simplePost.setX(0);
//            simplePost.setY(0);
//            CTPosH ph = inline.addNewPositionH();
//            ph.setRelativeFrom(STRelFromH.PAGE);//以整个页面为准的定位
//            ph.setPosOffset(x);//水平位置，针对RelativeFrom的一个偏移 1厘米=360045 ，1.1*360045
//            CTPosV pv = inline.addNewPositionV();
//            pv.setRelativeFrom(STRelFromV.PAGE);
//            pv.setPosOffset(y);//竖直位置，针对RelativeFrom的一个偏移 1.3*360045
//
//            /**
//             * 这个是此元素指定的其他程度应添加到每个边缘 （顶部、 底部、 左、 右）
//             * 以补偿应用于 DrawingML 对象的任何图形效果的图像
//             * 但目前好像用不到
//             */
//            CTEffectExtent efextent = inline.addNewEffectExtent();
//            efextent.setL(19050);
//            efextent.setT(0);
//            efextent.setR(0);
//            efextent.setB(0);
//
//            CTWrapNone wn = inline.addNewWrapNone();
//
//            CTNonVisualGraphicFrameProperties fp = inline.addNewCNvGraphicFramePr();
//            //*******************************************************
//
//
//            CTNonVisualDrawingProps docPr = inline.addNewDocPr();
//            long id = getParent().getDocument().getDrawingIdManager().reserveNew();
//            docPr.setId(id);
//            /* This name is not visible in Word 2010 anywhere. */
//            docPr.setName("Drawing " + id);
//            docPr.setDescr(filename);
//
//            CTPositiveSize2D extent = inline.addNewExtent();
//            extent.setCx(width);
//            extent.setCy(height);
//
//            // Grab the picture object
//            CTGraphicalObject graphic = inline.getGraphic();
//            CTGraphicalObjectData graphicData = graphic.getGraphicData();
//            CTPicture pic = getCTPictures(graphicData).get(0);
//
//            // Set it up
//            CTPictureNonVisual nvPicPr = pic.addNewNvPicPr();
//
//            CTNonVisualDrawingProps cNvPr = nvPicPr.addNewCNvPr();
//            /* use "0" for the id. See ECM-576, 20.2.2.3 */
//            cNvPr.setId(0L);
//            /* This name is not visible in Word 2010 anywhere */
//            cNvPr.setName("Picture " + id);
//            cNvPr.setDescr(filename);
//
//            CTNonVisualPictureProperties cNvPicPr = nvPicPr.addNewCNvPicPr();
//            cNvPicPr.addNewPicLocks().setNoChangeAspect(true);
//
//            CTBlipFillProperties blipFill = pic.addNewBlipFill();
//            CTBlip blip = blipFill.addNewBlip();
//            blip.setEmbed(parent.getPart().getRelationId(picData));
//
//            /********   增加  zhengmeng***********/
//            blip.setCstate(STBlipCompression.PRINT);//压缩状态
//
//            blipFill.addNewStretch().addNewFillRect();
//
//            CTShapeProperties spPr = pic.addNewSpPr();
//            CTTransform2D xfrm = spPr.addNewXfrm();
//
//            CTPoint2D off = xfrm.addNewOff();
//            off.setX(0);
//            off.setY(0);
//
//            CTPositiveSize2D ext = xfrm.addNewExt();
//            ext.setCx(width);
//            ext.setCy(height);
//
//            CTPresetGeometry2D prstGeom = spPr.addNewPrstGeom();
//            prstGeom.setPrst(STShapeType.RECT);
//            prstGeom.addNewAvLst();
//
//            // Finish up
//            XWPFPicture xwpfPicture = new XWPFPicture(pic, this);
//            pictures.add(xwpfPicture);
//            return xwpfPicture;
//        } catch (XmlException | SAXException e) {
//            throw new IllegalStateException(e);
//        }
//    }
//}
